﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseData;
using BaseData.UI;
using TaxBiz.SysConfig;
using TaxBiz.Tax;

namespace Admin.Tax
{
    public partial class TaxList :  BaseCommon.BasePage
    {
        protected int pageSize = 10;
        protected int page = 1;
        protected int allCount = 0;
        protected string pageUrl = string.Empty;
        protected string strWhere = string.Empty;
        protected int year = DateTime.Now.Year;
        protected string isTaxOK = string.Empty;
        protected string certificateID = string.Empty;//名称
        protected string houseType = string.Empty; //类型
        protected TaxCompleteBiz tcb = new TaxCompleteBiz();
        protected bool isHasModifyPower = false;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HasPower())
            {
                Jscript.AlertAndGoBack("您权限不足，不能操作");
                return;
            }
            isHasModifyPower = HasPower("TaxModify.aspx");
            this.InitData();
            string action = PageContext.GetRequest("action");
            if (!string.IsNullOrEmpty(action))
            {
                if (action.Trim().ToLower() == "stop")
                {
                    Delete();
                }
                return;
            }
            this.BindData();
        }

        //删除数据
        protected bool Delete()
        {
            string strID = PageContext.GetRequest("ID");
            string succPageUrl = Server.UrlDecode(Request["pageurl"]);
            int ID = 0;
            int.TryParse(strID, out ID);
            if (ID == 0)
            {
                Jscript.AlertAndGoBack("参数错误");
                return false;
            }
            bool isSucc = tcb.Delete(ID, UserLogin);
            if (!isSucc)
            {
                Jscript.AlertAndGoBack("删除完税失败");
                return false;
            }
            Jscript.AlertAndRedirect("删除完税成功", succPageUrl);
            return true;
        }

        protected void InitData()
        {
            pageUrl = Request.Url.AbsolutePath;
            //当前页码
            if (PageContext.GetRequest("page") != string.Empty)
            {
                int.TryParse(PageContext.GetRequest("page"), out page);
            }
            pageUrl += "?page=" + page;
            //名称
            certificateID = PageContext.GetRequest("txtCertificateID");
            if (certificateID != string.Empty)
            {
                pageUrl += "&txtCertificateID=" + certificateID;
                strWhere += " and certificateID = '" + certificateID + "'";
            }
            //税款属期
            if (PageContext.GetRequestInt("selYear").HasValue)
            {
                year = PageContext.GetRequestInt("selYear").Value;
            }
            else
            {
                year = DateTime.Now.Year;
            }
            pageUrl += "&selYear=" + year;
            strWhere += " and year = " + year;
            //房源类型
            houseType = PageContext.GetRequest("selHouseType");
            if (houseType != string.Empty)
            {
                pageUrl += "&selHouseType=" + houseType;
                strWhere += " and houseType = '" + houseType + "'";
            }
            //是否完税
            isTaxOK = PageContext.GetRequest("selIsTaxOK");
            if (isTaxOK != string.Empty)
            {
                pageUrl += "&selIsTaxOK=" + isTaxOK;
                strWhere += " and IsTaxOK = '" + isTaxOK + "'";
            }
            if (isQueryDepartmentOnly)
            {
                strWhere += " and CertificateID in (select CertificateID from HouseInfo where DepartmentID=" + UserLogin.DepartmentID + ")";
            }
        }

        protected void BindData()
        {
            this.rptDataList.DataSource = tcb.GetList(strWhere, pageSize, page, ref allCount);
            this.rptDataList.DataBind();
            //设置分页参数
            this.pageCountrol.CurPage = page;
            this.pageCountrol.PageSize = pageSize;
            this.pageCountrol.AllCount = allCount;
            this.pageCountrol.PageUrl = pageUrl;
            this.pageCountrol.PageName = "page";
        }

    }
}